<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<input style="ime-mode:Disabled" type="text" id="total"></input>
<button onClick="flgSubmitInfo()" >支付</button>
<script type="text/javascript" src="{$_C.hy_path}js/jquery-1.10.2.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="{$_C.hy_path}js/regular_main.js"></script>
<script>
	var pid = "{$info.wxid|default:'0'}";
	  wx.config({
	    debug: true, 
	    appId: '{$signPackage.appId}',
	    timestamp: {$signPackage.timestamp},
	    nonceStr: '{$signPackage.nonceStr}',
	    signature: '{$signPackage.signature}',
	    jsApiList: [
	      // 所有要调用的 API 都要加到这个列表中
	      'chooseWXPay',
		  'onMenuShareTimeline',
	      'onMenuShareAppMessage',
	    
	    ]
	  });
	   function showMsg(msg){
			alert(msg);
		 }
		 var isSend = false;
	function flgSubmitInfo(){
		if(isSend){
			showMsg("正在下单，请稍等...");
			return false;
		}
		var total = $("#total").val();
		if(!number_regular.test(total)){
			showMsg("请输入正确金额");
			return false;
		}
		isSend = true;
		var data = {
			total:total
		};
		 var url = "index.php?g=mobile&m=wechatpay&a=beforehandPay";
			$.post(url,data,function(res){
				if(res.error=="1"){
				}else{
					wx.chooseWXPay({
					    package: res.result.package,
					    nonceStr: res.result.nonceStr, 
					    paySign: res.result.paySign,
					    signType: res.result.signType,
					    timestamp: res.result.timeStamp, 
					    success: function (resu) {
							if(resu.errMsg == "chooseWXPay:ok"){
								successPayOrderQuery(res.out_trade_no);
	                        }
					    }
					});
				}
				isSend = false;
			},"json");
		}
function successPayOrderQuery(out_trade_no){
 	 var url = "index.php?g=mobile&m=wechatpay&a=orderquery&out_trade_no="+out_trade_no;
	$.get(url,function(res){
		if(res=="SUCCESS"){
			showMsg("下单成功");
//			window.location.href = "index.php?g=mobile&m=picture&a=record";
			//下单成功跳转
		}else{
			showMsg("下单失败");
		}
	},"text");
 }
</script>
</body>
</html>